from lib2to3.pgen2 import driver

from airtest.aircv import aircv, cv2_2_pil
from poco.proxy import UIObjectProxy
import pytesseract
from PIL import Image

from basic.device.Android import Android
from airtest.core.api import *



class trendsPage(Android):

    # trends = "com.cloudbae.lovenanning:id/menu_trends"
    Btn = "com.cloudbae.lovenanning:id/tab_tv3"



    view = "android.widget.Image"
    close_LoginFrame = "com.cloudbae.lovenanning:id/realNameFrame_close"

    # 点击发现
    # @classmethod
    # def clickTrends(self):
    #     self.poco(self.trends).click()
    #点击发现
    @classmethod
    def clickTrends(self):
        self.poco(self.Btn).click()
        print("点击生活页面")
        sleep(3)

    # 点击政务民生
    @classmethod
    def clickGover(self):
        self.poco(text='政务民生').click()
        print("----------------政务民生----------------")

    @classmethod
    def clickLife(self):
        self.poco(text='城市生活').click()
        print("----------------城市生活----------------")

    @classmethod
    def getData(self):
        closeHint = self.poco(self.close_LoginFrame)
        if closeHint.exists():
            closeHint.click()
        # 刷新一下
        self.poco(self.view).swipe('down')
        time.sleep(2)

        data= []
        # 页面数据的UI树结构
        text = self.poco("android.webkit.WebView").child("android.view.View").child("android.view.View").child("android.view.View").child("android.view.View")[1].child("android.view.View")[1].offspring("android.view.View")
        # 遍历当前页面的数据
        for i in text:
            textAll = i.get_text()
            data.append(textAll)
            # 循环，清理列表空字符串
            while "" in data:
                data.remove("")
        print(data)
        return data

    @classmethod
    def getCityData(self):
        closeHint = self.poco(self.close_LoginFrame)
        if closeHint.exists():
            closeHint.click()
        # 刷新一下
        # self.poco(self.view).swipe('down')
        # time.sleep(2)

        Citydata = []
        # 页面数据的UI树结构
        text = self.poco("android.webkit.WebView").child("android.view.View").child("android.view.View").child(
            "android.view.View").child("android.view.View")[1].child("android.view.View")[1].offspring(
            "android.view.View")
        # 遍历当前页面的数据
        for i in text:
            textAll = i.get_text()
            Citydata.append(textAll)
            # 循环，清理列表空字符串
            while "" in Citydata:
                Citydata.remove("")
        print(Citydata)
        return Citydata